package com.zm.core.controller;

import java.util.ArrayList;
import java.util.List;

import com.zm.core.model.Menu;
import com.zm.core.common.controller.BaseController;

public class MenuController extends BaseController {
	public void leftMenu()
	{
		List<Menu> menuList = Menu.dao.find(" SELECT id,pid,name,iconCls,url,openMode FROM s_menu WHERE state = 'a' ORDER BY sort ");
		
		List<Menu> parentList=new ArrayList<Menu>();
		
		for (Menu parentMenu : menuList)
		{
			long id = parentMenu.getLong("id");
			long pid = parentMenu.getLong("pid");
			if (pid==0)
			{
				List<Menu> childList=new ArrayList<Menu>();
				for (Menu childMenu : menuList)
				{
					//childMenu.put("child","");
					long cpid = childMenu.getLong("pid");
					if (cpid==id)
					{
						childList.add(childMenu);
					}
				}
				parentMenu.put("child", childList);
				parentList.add(parentMenu);
			}
		}
		
		renderJson(parentList);
	}


}
